<template>
  <ex-dialog
    width="800px"
    class="ex-diolog"
    title="比赛结束/修改比分"
    :visible="visible"
    @closeDialog="handleClose"
  >	
		<el-form :model="ruleForm" status-icon :rules="rules" ref="ruleForm" label-width="140px" class="demo-ruleForm">
      <el-form-item :label="ruleForm.oneName" prop="oneScore">
				<el-input type="text" v-model="ruleForm.oneScore" autocomplete="off" placeholder="请输入内容"></el-input>
			</el-form-item>
      <el-form-item :label="ruleForm.twoName" prop="twoScore">
				<el-input type="text" v-model="ruleForm.twoScore" autocomplete="off" placeholder="请输入内容"></el-input>
			</el-form-item>
      
			<el-form-item>
				<el-button type="primary" @click="submitForm('ruleForm')" :loading="loading">确认</el-button>
				<el-button @click="handleClose('ruleForm')">取消</el-button>
			</el-form-item>
		</el-form>
  </ex-dialog>
</template>
<script>
// components
import Loading from '@/components/Loading/index'
// api
import {
  supportScore,
  editModify,
  endModify
} from '@/api/blindBox/quizConfigOne'

export default {
  components: {
    Loading
  },
  props: {
    visible: Boolean,
    scoreStatus: String, 
    id: String,
  },
  data() {
    
    return {
      loading: false,
      betTypeList: [
        {id: 1,value: '神椰coco'}
      ],
      typeList: [
        {id: 1,value: '支持竞猜'},
        {id: 2,value: '冠军竞猜'},
      ],
      roleList: [],
      action: process.env.VUE_APP_BASE_API + "/common/v1/upload",
			ruleForm: {
        oneScore: '',//	队1得分
        twoScore: '',//	队2得分
				id: '',
      
			},
			rules: {
          oneScore: [
            { required: true,message: '请输入内容',trigger: 'blur' }
          ],
          twoScore: [
            { required: true,message: '请输入内容',trigger: 'blur' }
          ],
        }
    }
  },
  computed: {
   
  },
  created() {
    this.ruleForm.id = this.id
    console.log('this.id',this.id)
    this.getDetail()
	},
  methods: {
    getDetail(){
      var id = this.id
      supportScore(id).then(res => {
        this.ruleForm = res.result
      })
    },
    //新建子账号
    submitForm(formName) {
      console.log('formName',formName)
      this.$refs[formName].validate((valid) => {
        console.log('valid',valid)
        if (valid) {
          this.loading = true
          if(this.scoreStatus == 'editScore'){
            //修改比分
            var data = {
              ...this.ruleForm
            }
            editModify(data).then(res => {
              this.handleSuccess("修改成功")
              setTimeout(() => {
                this.loading = false
              }, 1000);
            }).catch(()=>{
              this.loading = false
            }).finally(() => {
              
            })
          }else if(this.scoreStatus == 'endScore'){
            //结束比赛
            var data = {
              ...this.ruleForm
            }
            endModify(data).then(res => {
              this.handleSuccess("操作成功")
              setTimeout(() => {
                this.loading = false
              }, 1000);
            }).catch(()=>{
              this.loading = false
            }).finally(() => {
            
            })
          }
            
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
    
		//取消
    handleClose(formName) {
      this.$emit('update:visible', false)
			// this.$refs[formName].resetFields();
    },
		//确认
		handleConfirm(){
			this.$emit('success', '你好')
		},
    handleSuccess(msg) {
      if (msg === '已拒绝') {
        var type = 'error'
      } else {
        var type = 'success'
      }
      this.$message({
        message: msg,
        type: type,
        duration: 1500,
        onClose: () => {
          this.handleClose()
          this.$emit('success')
        }
      })
    },
  }
}
</script>
<style lang="scss" scoped>
.ex-diolog {
  ::v-deep .ex--dialog--footer {
    border: none !important;
		padding: 0 !important;
  }
	::v-deep .ex--dialog--main {
    padding: 10px 20px !important; 
  }
}
::v-deep .avatar-uploader2 .el-upload {
  width: 100% !important;
}

.avatar-uploader2 {
  width: 130px;
  height: 130px;
  text-align: center;
  line-height: 130px;
  background-color: #fbfdff;
  border: 1px dashed #c0ccda;
}

.banner_img {
  width: 130px;
  height: 130px;
}
.el-input{
  width: 300px;
}
</style>